﻿// //   Copyright 2007-2011 Comdiv (F. Sadykov) - http://code.google.com/u/fagim.sadykov/
// //   Supported by Media Technology LTD 
// //    
// //   Licensed under the Apache License, Version 2.0 (the "License");
// //   you may not use this file except in compliance with the License.
// //   You may obtain a copy of the License at
// //    
// //        http://www.apache.org/licenses/LICENSE-2.0
// //    
// //   Unless required by applicable law or agreed to in writing, software
// //   distributed under the License is distributed on an "AS IS" BASIS,
// //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// //   See the License for the specific language governing permissions and
// //   limitations under the License.
// //   
// //   MODIFICATIONS HAVE BEEN MADE TO THIS FILE

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Comdiv.QWeb.Serialization.Extensions;
using Comdiv.QWeb.Serialization.Internals;

namespace Comdiv.QWeb.Serialization {
	public class MD5serializer : Serializer {
		protected override ISerializerImpl createImpl(string name, object value) {
			return new JsonSerializerImpl();
		}

		public override void serialize(string name, object value, TextWriter output) {
			var sw = new StringWriter();
			base.serialize(name, value, sw);
			var data = sw.ToString();
			var md5 = Convert.ToBase64String(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(data)));
			output.Write(md5);
		}
	}
}